
<form class="form-horizontal" role="form" id="myform">
    {dr_form_hidden()}
    <table id="mytable" data-show-export="true"></table>
</form>
<script type="text/javascript">
    var table_name = '{$mytable_name}';
    {if defined("SYS_TABLE_ISFOOTER") && SYS_TABLE_ISFOOTER}
    // 批量按钮设置为下面
    var is_foot = true;
    $("#toolbar label").hide();
    $("#toolbar button").hide();
    {else}
    // 批量按钮设置为上面
    var is_foot = $('#toolbar label').hasClass('table_select_all') == true ? false : true;
    {/if}
    var table_ignoreColumn = {php echo dr_count($list_field)+1;};
    var page_id = {max(1,intval($_GET['page']))};
    var post_token = {{csrf_token()}: "{csrf_hash()}"};
    var mytable = {json_encode($mytable)};
    if (mytable.foot_tpl) {
        var field_columns = [{
            checkbox: true,
            footerFormatter: function stockNumFormatter(data) {
                return is_foot ? mytable.foot_tpl : '';
            }
        }];
    } else {
        var field_columns = [];
    }

    // 按自定义字段显示
    {loop $list_field $i $tt}
    field_columns.push({
        field: '{$i}',
        title: '{dr_lang($tt.name)}',
        align: '{if $tt.center}center{else}left{/if}',
        switchable: true,
        sortable: true,
    {if $tt.width}width: '{$tt.width}px',{/if}
    visible: true
    });
    {/list}
        // 记录右侧操作按钮
        if (mytable.link_tpl) {
            field_columns.push({
                field: 'operation',
                title: '操作',
                formatter: function formatter (value, row, index) {
                    var html = mytable.link_tpl;
                    eval(mytable.link_var);
                    return html;
                },
                visible: true
            });
        }
</script>
<script src="{THEME_PATH}assets/global/plugins/bootstrap-table/bootstrap-table{if !IS_XRDEV}.min{/if}.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/bootstrap-table/tableExport{if !IS_XRDEV}.min{/if}.js" type="text/javascript"></script>
<link href="{THEME_PATH}assets/global/plugins/bootstrap-table/bootstrap-table.min.css"  rel="stylesheet" type="text/css" />
{if is_file(ROOTPATH.'api/pdfmake/pdfmake.min.js')}
<script type="text/javascript" src="{ROOT_URL}api/pdfmake/pdfmake.min.js"></script>
<script type="text/javascript" src="{ROOT_URL}api/pdfmake/gbsn00lp_fonts.js"></script>
<script type="text/javascript" src="{ROOT_URL}api/pdfmake/FileSaver.min.js"></script>
{/if}
<script type="text/javascript">

$(function (){
    var $mytable = $('#mytable').bootstrapTable({
        url : "{dr_now_url()}&is_ajax=1",
        surl : "{dr_web_prefix(SELF)}?is_ajax=1",
        method: 'get',
        striped: true,
        toolbar:"#toolbar",
        totalField:"msg",
        dataField:"data",
        selectItemName:"ids[]",
        idField:"id",
        cache: false,
        classes: "table table-striped table-bordered table-hover table-checkable dataTable ",
        queryParamsType: 'my',
        sidePagination: 'server',
        silent: true,
        showRefresh: {if $is_search && !$is_mobile}true{else}false{/if},
        showFullscreen: $('#table-search-tool-submit').hasClass('btn'),
        showToggle: true,
        showColumns: true,
        showExport: {if $is_show_export && $is_search && !$is_mobile}true{else}false{/if},
        uniqueid: "id",
        singleSelect: false,
        clickToSelect:false,
        sortName: "",
        sortOrder: "",
        pageSize: {$mytable_pagesize},
        pageNumber: page_id,
        pageList: "[{php echo $mytable_pagelist ? $mytable_pagelist : '10, 25, 50, 100, 200, 300'}]",
        {if !\Phpcmf\Service::IS_PC_USER()}
        paginationHAlign: 'center',
        paginationDetailHAlign: 'center',
        paginationSuccessivelySize: 0,
        paginationPagesBySide: 0,{/if}
        search: false,
        pagination: true,
        paginationShowPageGo: true,
        showFooter:is_foot ,
        exportTypes:['csv', 'txt', 'doc', 'excel'{if is_file(ROOTPATH.'api/pdfmake/pdfmake.min.js')}, 'pdf'{/if}],
        onPostBody:function () {
            //合并页脚
            if (is_foot && mytable.foot_tpl) {
                var footer_tbody = $('.fixed-table-body table tfoot');
                var footer_tr = footer_tbody.find('>tr');
                var footer_td = footer_tr.find('>th');
                var footer_td_1 = footer_td.eq(0);
                for(var i=1;i<footer_td.length;i++) {
                    footer_td.eq(i).remove();
                }
                footer_td_1.attr('colspan', footer_td.length).show();
            } else {
                $('.fixed-table-body table tfoot').remove();
            }
        },
        onLoadSuccess: function onLoadSuccess(data) {
            if (is_foot && mytable.foot_tpl) {
                var td_size = $('.fixed-table-body table tbody tr').length;
                var dp_size = $('.fixed-table-body table tfoot .dropdown-menu li').length;
                if (dp_size > td_size) {
                    $('.fixed-table-body table tfoot .dropdown-menu').attr("style", "max-height: "+(40*td_size)+"px;overflow-y: scroll;");
                }
            }
            return false;
        },
        columns: field_columns,
            queryParams: function queryParams(params) {
            var temp = {
                page : params.pageNumber,
                pagesize : params.pageSize,
                order : params.sortName+' '+params.sortOrder,
            };
            return temp;
        }
    });
    $("#table-search-tool-submit").click(function () {
        $mytable.bootstrapTable('refresh');
    });
    $(".table-search-tool input").keydown(function(e) {
        if (e.keyCode == 13) {
            $mytable.bootstrapTable('refresh');
        }
    });

});
</script>